import json
import requests

url = "http://api.proxy.ipidea.io/getProxyIp?num=100&tag=static_us_balance&return_type=json&lb=1&sb=0&flow=1&protocol=http"
res = requests.get(url=url, verify=False)
res = json.loads(res.text)
if res['code'] == 0 and res['success'] == True:
    # 清空文件
    with open('proxy.txt', 'w') as file:
        pass
    # 写入IP+端口
    for i in res['data']:
        # print(str(i['ip']) + ":" + str(i['port']))
        with open('proxy.txt', 'a') as w:
            w.write(str(i['ip']) + ":" + str(i['port']) + '\n')
            w.close()
    print('成功获取' + str(len(res['data'])) + '个代理IP-')

else:
    print('获取失败：' + res['msg'])
